package net.bac.sbe.common.main;

import java.util.List;

import net.bac.sbe.common.logger.LoggerService;

import org.sonar.wsclient.Host;
import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.connectors.HttpClient4Connector;
import org.sonar.wsclient.services.Measure;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

public final class WSTestClient {
	
	private WSTestClient(){
		super();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Sonar sonar = new Sonar(new HttpClient4Connector(new Host("http://localhost:9000")));
		ResourceQuery query = ResourceQuery.createForMetrics("Redir:Redir", "function_complexity", "blocker_violations", "critical_violations", "major_violations");
		query.setDepth(-1);
		query.setScopes("FIL");
		query.setQualifiers("CLA");
		query.setIncludeTrends(true);
		List<Resource> resources = sonar.findAll(query);
		for (Resource resource : resources) {
			Measure measure = resource.getMeasure("function_complexity");
			Measure measure1 = resource.getMeasure("blocker_violations");
			Measure measure2 = resource.getMeasure("critical_violations");
			Measure measure3 = resource.getMeasure("major_violations");
			LoggerService.logInformation(resource.getLongName() + " Complejidad: " + ((null != measure)?measure.getValue():"0")
					+ " Blocker: " + ((null != measure1)?measure1.getValue():"0")
					+ " Critical: " + ((null != measure2)?measure2.getValue():"0")
					+ " Major: " + ((null != measure3)?measure3.getValue():"0")
					);
			
		}
	}

}
